﻿
using System.Diagnostics.Contracts;
using Adalbertus.BudgetPlanner.Domain;
using Caliburn.Micro;

namespace Adalbertus.BudgetPlanner.ViewModels.ExpenseTypes
{
    public class ExpenseTypeVM : PropertyChangedBase
    {
        private CashFlow _wrappedCashFlow;
        public CashFlow WrappedCashFlow
        {
            get
            {
                Contract.Ensures(Contract.Result<CashFlow>() != null);
                return _wrappedCashFlow;
            }
        }

        public ExpenseTypeVM(CashFlow wrappedCashFlow)
        {
            if (wrappedCashFlow == null)
            {
                _wrappedCashFlow = new CashFlow();
            }
            else
            {
                _wrappedCashFlow = wrappedCashFlow;
            }
        }

        public string Name
        {
            get { return _wrappedCashFlow.Name; }
            set
            {
                _wrappedCashFlow.Name = value;
                NotifyOfPropertyChange(() => Name);
            }
        }

        public string Description
        {
            get { return _wrappedCashFlow.Description; }
            set
            {
                _wrappedCashFlow.Description = value;
                NotifyOfPropertyChange(() => Description);
            }
        }

        public bool IsReadOnly
        {
            get { return _wrappedCashFlow.Saving != null; }
        }
    }
}
